<?php

require "database.php";

$__victory__=(int)$_GET["victory"];
$is_yes=$_GET["is_yes"];

$__demo__=file_get_contents("demo.json");
$__demo__=json_decode($__demo__,1);

if($__demo__["victory2"]>0){
    $__demo__["victory2"]=$__demo__["victory2"]*-1;
}



if($is_yes=="yes"){
    $__demo__["vk"]     =$__demo__['vk']+$__victory__;
    $__demo__["victorytop"]=$__demo__["victorytop"]+$__victory__;
}else{
    $__demo__["vk"]     =$__demo__['vk']-$__victory__;
    $__demo__["victorykui"]=$__demo__["victorykui"]+$__victory__;
}

$_status=0;

// $__fs__=abs($__demo__["victorytop"]-$__demo__["victorykui"]);



// if($__demo__["victorytop"]>=$__demo__["victory"] || $__demo__["victorykui"]>=$__demo__["victory"]){
// if($is_yes=="yes"){
if($__demo__["vk"]>0){
    if( $__demo__["vk"] >= $__demo__["victory"] ){
        $_status=1;
        $__demo__["stopsum"]+=1;
        $stopsum=$__demo__["stopsum"];
    }else{
        $_status=0;
    }
}else{
    if( $__demo__["vk"] <= $__demo__["victory2"] ){
        $_status=1;
        $__demo__["stopsum"]+=1;
        $stopsum=$__demo__["stopsum"];
    }else{
        $_status=0;
    }
}
// }else{
//     if( $__fs__ >= $__demo__["victory2"] ){
//         $_status=1;
//         $__demo__["stopsum"]+=1;
//         $stopsum=$__demo__["stopsum"];
//     }else{
//         $_status=0;
//     }
// }





$__demo__=json_encode($__demo__,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
file_put_contents("demo.json",$__demo__);


if($_status==1){
    return json([
        "code"=>200,
        "msg"=>"stop",
        "count"=>$stopsum
    ]);
}else{
    return json([
        "code"=>200,
        "msg"=>"continue"
    ]);
}

